#ifndef Qt_WINDOW__H
#define Qt_WINDOW__H
#include <QMainWindow>
#include <QDir>
#include <QStandardPaths>
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QDebug>

#include <QPainter>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QList>
#include <QTimer>

class QWindow : public QMainWindow
{
    Q_OBJECT

public:
    QWindow(QWidget *parent = nullptr);
    ~QWindow();
    void SetStyleWindow(QString filepath);
    void SetWidgets(void);
    void SerialPortNumInit(void);
    void SerialBaudRateInit(void);
    void SerialDataBitsInit(void);
    void SerialStopBitsInit(void);
    void SerialParityBitsInit(void);
    void SerialFlowConstrolInit(void);

    void SerialObjectInit(void);

    bool isPortsChanged(const QList<QSerialPortInfo> &newPorts,
                        const QList<QSerialPortInfo> &oldPorts);
    void GetAvaliablePortName(void);

public slots:
    void FlushSerialPort(void);

private:
    QString styleFilePath = QDir::currentPath() + "/resource/style/theme.qss";
    quint16 Width = 800;
    quint16 Hight = 480;

    QPushButton *connectButton;

    QComboBox *SerialPortNum;
    QLabel *SerialPortNumLabel;

    QComboBox *SerialBaudRate;
    QLabel *SerialBaudRateLabel;

    QComboBox *SerialDataBits;
    QLabel *SerialDataBitsLabel;

    QComboBox *SerialStopBits;
    QLabel *SerialStopBitsLabel;

    QComboBox *SerialParityBits;
    QLabel *SerialParityBitsLabel;

    QComboBox *SerialFlowConstrol;
    QLabel *SerialFlowConstrolLabel;

private:
    QSerialPort *serial;
    QList<QSerialPortInfo> serial_port;
    QString ChosePortName;
    QString ChoseBaudRate;
    QString ChoseDataBits;
    QString ChoseStopBits;
    QString ChoseParity;
    QString ChoseFlowConstrol;
    QTimer *serialTimer;
};

#endif // !Qt_WINDOW__H
